import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Random;


public class Main2 {

	
	public static void main(String[] args) {
		int[] arr1 = {1,0,0,1,1,1,0,1,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,0,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,1,0,0,1,1,1,1};
		int[] arr2 = {1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,1,1,0,1,1,1,0,1,0,1,0,0,1,1,0,0,0,0,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,1,1,0};
		int[] arr3 = new int[70];
		for(int i=0;i<70;i=i+1){
			arr3[i]=1;
		}
		int[] arr4 = {0,1,1,1,1,0,1,1,1,0,1,0,0,1,0,1,1,1,1,0};
		int[] arr5 = {0,0,1,1,0,0,1,1,1,1,1,0,1,0,1,1,1,1,0,1};
		int[] arr6 = {1,1,1,1,0,1,1,1,1,0,1,0,1,1,1,1,0,1,1,1}; 
		
		int[] arr7 = {1,1,1,0,1,1,1,0,1,1,0,1,0,1,0,1,1,1,1,0,0,0,1,1,1,1,1,0,1,1,1,1,0,0,1,1,0,0,0,0,0,1,0,1,0,1,1,1,1,1,1,1,0,0,1,1,0,1,1,0,1,0,1,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,0,1,0,0,1,1,1,0,0,1,0,0,1,1,0,1,1,1,0,1,0,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,1,1,0,0,1,1,1,0,1,1,1,0,1,1,0,0,0,1,0,0,0,1,1,0,1,1,0,1,1,1,0,0,1,0,0,1,1,1,1,1,1,0,1,1,0,1,1,1,0,1,1,0,0,0,0,1,0,1,0,1,1,1,1,1,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1,1,1,0,0,1,0,1,0,0,1,1,0,1,0,1,1,0,0,1,1,0,0,0,0,1,1,1,0,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,0,0,0,0,1,1,1,0,0,1,1,1,0,1,1,1};
		int[] arr10= {0,1,1,1,0,1,0,1,0,1,0,0,0,1,0,1,1,1,1,1,1,0,1,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,0,0,1,1};
		int[] arr11= {0,1,0,1,0,1,0,1,0,0,0,0,1,1,0,1,0,1,1,1,1,0,1,1,0,1,0,0,0,0,0,1,0,1,0,1,0,0,1,1,1,0,1,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,0,1,1};
		int[] arr12= {0,1,1,0,0,0,1,1,0,1,0,1,1,1,0,1,1,0,0,1,0,0,1,0,0,0,0,0,0,1,1,1,1,1,0,1,1,1,0,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1,0,0,0,0,1,1,0,0,0,1,1,1,1,0,0,1};
		int[] arr13= {0,0,0,0,1,0,0,0,0,1,0,1,0,0,0,1,1,0,0,1,0,0,0,1,0,1,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,0,0,1,1,0,1,0,1,0,1,1,1,1,1,1};
		int[] arr14= {1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,1,1,1,0,1,1,0,0,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,1,0,1,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,1,0,1};
		//tit 4 tat
		int[] temp1 = new int[Data.chromozomSize];
		for(int i=0; i < Data.chromozomSize ; i++){
			if(i%2 == 0)
				temp1[i]=0;
			else
				temp1[i]=1;
		}
		temp1[Data.chromozomSize-1]=0;
		Chromosome tit4tat = new Chromosome(temp1);
		//always 1
		int[] temp2 = new int[Data.chromozomSize];
		for(int i=0; i < Data.chromozomSize ; i++){
			temp2[i]=1;
		}
		Chromosome always1 = new Chromosome(temp2);
		
		
		
		//Chromosome winner=new Chromosome(arr14);
		//Chromosome winner=tit4tat;
		//Chromosome winner=always1;
		Chromosome winner = fromInputFile(new File("test.txt"));
		
		/*
		for(int i=0; i < winner.data.length; i++)
			System.out.print(winner.data[i]);
		*/
		for(int i=0;i<10000;i++){
			Random r= new Random();
			int tempArr[]=new int[Data.chromozomSize];
			for(int j=0;j<Data.chromozomSize;j++){
				tempArr[j]=r.nextInt(2);
			}
			Chromosome temp = new Chromosome(tempArr);
			winner.play(temp);
		}
		System.out.println(winner.gamesWon);
		System.out.println(winner.timeInPrison);
	}

	public static Chromosome fromInputFile(File file){
		
		Chromosome result=null;
		FileInputStream fis = null;
	    BufferedInputStream bis = null;
	    DataInputStream dis = null;

	    try {
	      fis = new FileInputStream(file);

	      // Here BufferedInputStream is added for fast reading.
	      bis = new BufferedInputStream(fis);
	      dis = new DataInputStream(bis);
	      // dis.available() returns 0 if the file does not have more lines.
	      
    	  String data = dis.readLine();
    	  int []arr = new int[data.length()];
    	  for(int i=0 ; i < arr.length ; i++)
    		  arr[i]=Integer.parseInt(data.substring(i, i+1));
    	  result = new Chromosome(arr);

	      // dispose all the resources after using them.
	      fis.close();
	      bis.close();
	      dis.close();

	    } catch (FileNotFoundException e) {
	      e.printStackTrace();
	    } catch (IOException e) {
	      e.printStackTrace();
	    }
	    
	    return result;
	}
}
